#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int TEST_CASES = 25; // 生成25个测试用例
random_device rd;
mt19937 gen(rd());

// 生成一个随机整数
int randomInt(int min, int max) {
    return uniform_int_distribution<int>(min, max)(gen);
}

// 生成测试用例
void test(int testCase, ofstream& fout) {
    int n, q;
    vector<tuple<int, int, int>> presents; // 存储礼物的(P, A, B)值
    vector<int> initialMoods; // 存储初始心情值

    // 根据测试用例编号生成不同难度的测试数据
    if (testCase <= 5) {
        // 简单测试用例
        n = randomInt(1, 10);
        q = randomInt(1, 10);
    }
    else if (testCase <= 15) {
        // 中等测试用例
        n = randomInt(10, 1000);
        q = randomInt(10, 1000);
    }
    else {
        // 困难测试用例
        n = randomInt(1000, 10000);
        q = randomInt(1000, 2000);
    }

    // 生成礼物数据
    presents.resize(n);
    initialMoods.resize(q);

    // 根据测试用例类型生成不同特性的数据
    if (testCase == 1) {
        // 样例1
        n = 4;
        q = 11;
        presents = {
            {3, 1, 4},
            {1, 5, 9},
            {2, 6, 5},
            {3, 5, 8}
        };
        initialMoods = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    }
    else if (testCase == 2) {
        // 样例2
        n = 3;
        q = 1;
        presents = {
            {500, 500, 500},
            {500, 500, 500},
            {500, 500, 500}
        };
        initialMoods = { 1000000000 };
    }
    else if (testCase == 3) {
        // 样例3
        n = 20;
        q = 20;
        presents = {
            {124, 370, 105}, {280, 200, 420}, {425, 204, 302}, {435, 141, 334},
            {212, 287, 231}, {262, 410, 481}, {227, 388, 466}, {222, 314, 366},
            {307, 205, 401}, {226, 460, 452}, {336, 291, 119}, {302, 104, 432},
            {478, 348, 292}, {246, 337, 403}, {102, 404, 371}, {368, 399, 417},
            {291, 416, 351}, {236, 263, 231}, {170, 415, 482}, {101, 339, 184}
        };
        initialMoods = { 1162, 1394, 1695, 2501, 3008, 3298, 4053, 4093, 4330, 5199,
                        5302, 5869, 5875, 6332, 6567, 7483, 7562, 7725, 9723, 9845 };
    }
    else if (testCase <= 8) {
        // 一些特殊情况
        for (int i = 0; i < n; ++i) {
            int p, a, b;
            if (testCase == 4) {
                // 所有礼物参数相等
                p = 100;
                a = 100;
                b = 100;
            }
            else if (testCase == 5) {
                // 礼物价值很小，心情变化很大
                p = randomInt(1, 10);
                a = randomInt(400, 500);
                b = randomInt(400, 500);
            }
            else if (testCase == 6) {
                // 礼物价值很大，心情变化很小
                p = randomInt(400, 500);
                a = randomInt(1, 10);
                b = randomInt(1, 10);
            }
            else if (testCase == 7) {
                // 心情增加值大于减少值
                p = randomInt(1, 500);
                a = randomInt(300, 500);
                b = randomInt(1, 100);
            }
            else {
                // 心情减少值大于增加值
                p = randomInt(1, 500);
                a = randomInt(1, 100);
                b = randomInt(300, 500);
            }
            presents[i] = make_tuple(p, a, b);
        }

        // 生成初始心情值
        for (int i = 0; i < q; ++i) {
            if (testCase == 4) {
                // 初始心情值很小
                initialMoods[i] = randomInt(0, 50);
            }
            else if (testCase == 5) {
                // 初始心情值很大
                initialMoods[i] = randomInt(10000, 1000000000);
            }
            else {
                // 随机初始心情值
                initialMoods[i] = randomInt(0, 10000);
            }
        }
    }
    else {
        // 随机生成礼物数据
        for (int i = 0; i < n; ++i) {
            int p = randomInt(1, 500);
            int a = randomInt(1, 500);
            int b = randomInt(1, 500);
            presents[i] = make_tuple(p, a, b);
        }

        // 随机生成初始心情值
        for (int i = 0; i < q; ++i) {
            if (testCase >= 20) {
                // 对于困难测试用例，生成更大范围的初始心情值
                initialMoods[i] = randomInt(0, 1000000000);
            }
            else {
                initialMoods[i] = randomInt(0, 100000);
            }
        }
    }

    // 输出测试数据
    fout << n << endl;
    for (int i = 0; i < n; ++i) {
        int p, a, b;
        tie(p, a, b) = presents[i];
        fout << p << " " << a << " " << b << endl;
    }

    fout << q << endl;
    for (int i = 0; i < q; ++i) {
        fout << initialMoods[i] << endl;
    }
}

void mk_in() {
    // 创建testdata目录（如果不存在）
    if (system("mkdir -p testdata") != 0) {
        cerr << "创建testdata目录失败" << endl;
        return;
    }

    for (int i = 1; i <= TEST_CASES; ++i) {
        string in_name = "testdata/" + to_string(i) + ".in";
        ofstream fout(in_name);
        test(i, fout);
        fout.close();
        cout << "生成【" << i << ".in】数据成功\n";
    }
}

void mk_out() {
    for (int i = 1; i <= TEST_CASES; ++i) {
        string in_name = "testdata/" + to_string(i) + ".in";
        string out_name = "testdata/" + to_string(i) + ".out";
        string cmd = "./std < " + in_name + " > " + out_name;
        if (system(cmd.c_str()) != 0) {
            cerr << "生成【" << i << ".out】数据失败\n";
            return;
        }
        cout << "生成【" << i << ".out】数据成功\n";
    }
}

int main() {
    // 编译标准程序
    if (system("g++ std.cpp -o std -std=c++17") != 0) {
        cerr << "编译标准程序失败" << endl;
        return 1;
    }

    mk_in();
    mk_out();
    return 0;
}